package com.example.springbootjdbc.curd;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * @Auther: 郭敬仰
 * @Date: 2019/7/9 17:41
 * @Description:
 */
@Component
public class JdbcTempTest {
    @Autowired
    private JdbcTemplate jdbcTemplate;

    public void findAll() {
        List<Map<String, Object>> maps = jdbcTemplate.queryForList("SELECT * FROM user");
        List<String> list =  jdbcTemplate.queryForList("SELECT server FROM config",String.class);
        System.out.println(maps);
    }

    public void insert() {
        jdbcTemplate.execute("INSERT INTO user (name,age,email) VALUES ('www.qq.com') ");
    }

    public void update() {
        jdbcTemplate.execute("UPDATE user SET email = 'www.baidu.com'");
    }

    public void delete() {
        jdbcTemplate.execute("DELETE FROM user WHERE id = 5 ");
    }
}
